package com.enjoyor.soa.traffic.restt.tpcms.dubbo.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.dto.tpcms.RltBayonetDto;
import com.enjoyor.soa.traffic.api.dto.tpcms.RltBayonetZoneDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tpcms.IDubboRltBayonetZoneService;
import com.enjoyor.soa.traffic.api.ubms.dto.OffsiteInfoDto;
import com.enjoyor.soa.traffic.api.ubms.service.dubbo.DubboOffsiteInfoService;
import com.enjoyor.soa.traffic.restt.tpcms.dubbo.IRltBayonetZoneConsumeService;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@Component
public class RltBayonetZoneConsumeService implements IRltBayonetZoneConsumeService {

    @Reference(version = "1.0.0", timeout = 10000)
    private IDubboRltBayonetZoneService dubboRltBayonetZoneService;

    @Reference(timeout = 10000)
    private DubboOffsiteInfoService dubboOffsiteInfoService;

    /**
     * 查询关联卡口
     */
    @Override
    @SuppressWarnings("unchecked")
    public ResultPojo getRltBayonetList(String relationId) {
    	//获取关联卡口数据
        List<RltBayonetZoneDto> rltBayonetList = (List<RltBayonetZoneDto>) dubboRltBayonetZoneService.getRltBayonetList(relationId).getResultList();
        List<RltBayonetDto> rltBayonetDtoList = new ArrayList<RltBayonetDto>();
        //获取关联卡口坐标数据
        for (RltBayonetZoneDto rltBayonetZone : rltBayonetList) {
            RltBayonetDto rltBayonetDto = new RltBayonetDto();
            ResultPojo offsiteInfo = dubboOffsiteInfoService.getOffsiteInfoById(rltBayonetZone.getBayonetId());
            List<OffsiteInfoDto> OffsiteInfoDtoList = (List<OffsiteInfoDto>) offsiteInfo.getResultList();
            if (OffsiteInfoDtoList != null && OffsiteInfoDtoList.size() > 0) {
                OffsiteInfoDto offsiteInfoDto = OffsiteInfoDtoList.get(0);
                rltBayonetDto.setCoordX(offsiteInfoDto.getCoordX());
                rltBayonetDto.setCoordY(offsiteInfoDto.getCoordY());
            }
            rltBayonetDto.setRltBayonetZone(rltBayonetZone);
            rltBayonetDtoList.add(rltBayonetDto);
        }
        return new ResultPojo(rltBayonetDtoList);
    }

    /**
     * 关联卡口
     */
    @Override
    public ResultPojo insertRltBayonet(List<RltBayonetZoneDto> rltBayonetZones, String username) {
        return dubboRltBayonetZoneService.insertRltBayonet(rltBayonetZones, username);
    }

    /**
     * 取关卡口
     */
    @Override
    public ResultPojo deleteRltBayonet(RltBayonetZoneDto rltBayonetZone, String username) {
        return dubboRltBayonetZoneService.deleteRltBayonet(rltBayonetZone, username);
    }

    /**
     * 地图上单个卡口关联
     */
    @Override
    public ResultPojo insertRltBayonetForOne(RltBayonetZoneDto rltBayonetZone, String username) {
        return dubboRltBayonetZoneService.insertRltBayonetForOne(rltBayonetZone, username);
    }

}
